<template>
  <div class="mnt-dialog form-container">
    <el-form ref="form" :model="formModel" label-width="160px" :rules="rules">
      <el-row style="text-align: center">
        <el-col :span="12">
          <el-form-item label="追溯工位:" prop="ulocNo">
            <el-select
              v-model="formModel.ulocNo"
              clearable
              filterable
              :disabled="true"
            >
              <el-option
                v-for="item in ulocOptions"
                :key="item.ulocNo"
                :label="item.ulocNo+'-'+item.ulocName"
                :value="item.ulocNo"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="整车物料编码:" prop="materialNo">
            <el-select
              v-model="formModel.materialNo"
              clearable
              filterable
              :disabled="true"
            >
              <el-option
                v-for="item in carMaterialDataOptions"
                :key="item.materialNo"
                :label="item.materialNo+'-'+item.materialDesc"
                :value="item.materialNo"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="零件追溯件代码:" prop="partTrackNo">
            <el-select
              v-model="formModel.partTrackNo"
              clearable
              filterable
              :disabled="true"
            >
              <el-option
                v-for="item in partTrackNoOptions"
                :key="item.partTrackNo"
                :label="item.partTrackNo+'-'+item.partTrackNoName"
                :value="item.partTrackNo"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="零件物料编码:" prop="groupNumber">
            <el-select
              v-model="formModel.groupNumber"
              clearable
              filterable
            >
              <el-option
                v-for="item in partTrackGroupNumOptions"
                :key="item.groupNumber"
                :label="item.materialNo+'-'+item.materialDesc"
                :value="item.groupNumber"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="对称件标记:" prop="symmetricalPartTab">
            <hey-select
              v-model="formModel.symmetricalPartTab"
              clcd="ind_cd"
              :disabled="true"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="前中后标记:" prop="locationTab">
            <hey-select
              v-model="formModel.locationTab"
              clcd="location_tab"
              :disabled="true"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-row class="submit-area">
      <el-col :span="24">
        <el-button @click="closeDialog">取消</el-button>
        <el-button type="primary" @click="handleSubmit()">确定</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>

export default {
  name: 'OrderPartTrackMnt',
  props: ['pageType', 'editData'],
  data() {
    return {
      tableData: [],
      ulocOptions: [],
      carMaterialDataOptions: [],
      partTrackNoOptions: [],
      partTrackGroupNumOptions: [],
      formModel: {
        rcrdId: '',
        ulocNo: '',
        materialNo: '',
        partTrackNo: '',
        groupNumber: '',
        symmetricalPartTab: '',
        locationTab: ''
      },
      rules: {}
    }
  },
  computed: {},
  mounted() {
    this.init()
  },
  methods: {
    init() {
      this.$form = this.$refs.form
      const { pageType, editData, formModel } = this
      const param = { status: '1' }
      this.assignData(editData, formModel)
      this.getUlocList(param)
      this.getPartTrackNoOptions(param)
      const carParam = { materialTypeKey: 'car', status: '1' }
      this.getCarMaterialDataOptions(carParam)
      const partParam = { status: '1', partTrackNo: this.formModel.partTrackNo }
      this.getPartTrackGroupNumOptions(partParam)
      this.initRules()
    },
    initRules() {
      const REQUIRED_MSG = this.CONST.REQUIRED_MSG
      this.rules = {
        groupNumber: [{ required: true, message: REQUIRED_MSG, trigger: ['change', 'blur'] }]
      }
      this.$nextTick(_ => {
        this.$form.clearValidate()
      })
    },
    /** 查询追溯工位列表 */
    getUlocList(param) {
      this.get('/tmBasUloc/queryTmBasUloc', param).then(res => {
        this.ulocOptions = res.list
      })
    },
    /** 查询整车物料编码列表 */
    getCarMaterialDataOptions(param) {
      this.get('/materialData/listMaterialData', param).then(res => {
        this.carMaterialDataOptions = res
      })
    },
    /** 查询零件追溯件代码 */
    getPartTrackNoOptions(param) {
      this.get('/partTrackNo/listPartTrackNo', param).then(res => {
        this.partTrackNoOptions = res
      })
    },
    /** 查询零件追溯件组号代码列表 */
    getPartTrackGroupNumOptions(param) {
      this.get('/partTrackGroupNum/listPartTrackGroupNum', param).then(res => {
        this.partTrackGroupNumOptions = res
      })
    },
    /** 修改新增提交 */
    handleSubmit() {
      this.$refs.form.validate(valid => {
        if (valid) {
          const tip = '修改成功！'
          const url = '/orderQasKeyPartTrack/updateOrderQasKeyPartTrack'
          this.post(url, this.formModel).then(res => {
            this.$info(tip, () => {
              this.$emit('queryOrderPartTrackSuc', res)
              this.closeDialog()
            })
          })
        }
      })
    },
    closeDialog() {
      this.$parent.$emit('update:visible', false)
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
